package com.gx.ring.service.impl;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.log4j.Logger;

import com.google.gson.Gson;
import com.gx.exception.DataBaseConnectFailedException;
import com.gx.ring.dao.RingBaseInterfaceDAO;
import com.gx.ring.dao.RingExistCorpIDInterfaceDAO;
import com.gx.ring.service.QueryInterfaceService;
import com.gx.ring.service.QueryServiceFactory;
import com.gx.util.DBHelperOracl;

public class QueryInterfaceImplService implements QueryInterfaceService {
	private static Logger log = Logger.getLogger(QueryInterfaceImplService.class);
	@Override
	public String qureyByphNumber(String option, String phNumber) {
		String obj = null;
		try {
			Connection conn = DBHelperOracl.getConnection();
			RingBaseInterfaceDAO<?> rbf = QueryServiceFactory.getDAO(option, conn);
			Gson gson = new Gson();
			obj = gson.toJson(rbf.queryByphNumber(phNumber));
		} catch (DataBaseConnectFailedException | SQLException e) {
			log.info(e.getCause(),e);
		}

		return obj;
	}

	public String queryByCorpCode(String option, String corpCode) {
		String obj = null;
		try {
			Connection conn = DBHelperOracl.getConnection();
			RingExistCorpIDInterfaceDAO<?> rbf = (RingExistCorpIDInterfaceDAO<?>) QueryServiceFactory.getDAO(option, conn);
			Gson gson = new Gson();
			obj = gson.toJson(rbf.queryByCorpCode(corpCode));
		} catch (DataBaseConnectFailedException | SQLException e) {
			log.info(e.getCause(),e);
		}

		return obj;
	}
}
